#include "my_combo.h"
#include <QListView>

My_Combo::My_Combo(const QString &title, QWidget *parent) : QWidget(parent)
{
    name = new QLabel(title, this);
    name->setAlignment(Qt::AlignCenter);
    combo = new QComboBox(this);

    // 设置样式表时会起作用
    QListView* listView = new QListView();
    combo->setView(listView);

    box = new QHBoxLayout();
    box->addWidget(name);
    box->addWidget(combo);
    box->setContentsMargins(LEFT_M, TOP_M, RIGHT_M, BOTTOM_M);
    box->setSpacing(SPACE_SON);
    this->setLayout(box);
}

void My_Combo::addItems(const QStringList &texts)
{
    combo->addItems(texts);
}

void My_Combo::setCurrentIndex(int index)
{
    combo->setCurrentIndex(index);
}

QString My_Combo::currentText()
{
    return combo->currentText();
}
